<template>
	<view class="card bg-white u-m-t-20 border-r-6">
		<view @click="goInfo" class="u-flex u-p-28">
			<view class="u-m-r-28" v-show="item.cover">
				<u-image border-radius="14px" width="115px" height="115px" :src="item.cover">
				</u-image>
			</view>
			<view class="right" :style="{width:item.cover?'61%':'100%',height:item.cover?'115px':'auto'}">
				<view class="u-font-32 u-flex u-row-between">
					<text class="u-line-1 title">{{item.title}}</text>

					<view class="u-rela">
						<u-badge size="mini" :is-center="true" type="error" :count="item.comment_unread_count">
						</u-badge>
						<u-image src="@/pagesMy/static/comment.png" width="18px" height="18px"></u-image>
					</view>




					<!-- <u-tag shape="circle" border-color="#FEF2BF" color="#333" :text="item.is_show === 1?'已上架':'已下架'"
						size="mini" mode="plain" /> -->

				</view>
				<view class="u-m-t-16 u-m-b-16">
					<u-tag class="u-m-r-8" color="#333" :text="item.category" size="mini" bg-color="#FEF2BF"
						mode="dark" />
				</view>
				<view class="u-line-3 u-font-12 color-80 u-m-t-8">{{item.content}}</view>
			</view>


		</view>
		<view class="border-t u-font-10 color-80 u-p-28 u-flex u-row-between">
			<text>{{item.create_time}}</text>
			<view class="u-flex">
				<u-tag @click="goEdit" class="u-m-l-28" shape="circle" color="#808080" text="编辑" size="mini"
					mode="plain" />
				<!-- <u-tag @click="setIsShow" class="u-m-l-28" shape="circle" color="#808080"
					:text="item.is_show === 1?'设为已下架':'设为已上架' " size="mini" mode="plain" /> -->
				<u-tag @click="remove" class="u-m-l-28" shape="circle" color="#FF3C26" text="删除" size="mini"
					mode="plain" />
			</view>
		</view>
	</view>
</template>

<script>
	import {
		setPostIsShow,
		myPostDel
	} from '@/api/user'
	export default {
		props: ['item'],
		name: "postCard",
		data() {
			return {

			};
		},
		methods: {
			async setIsShow() {
				const res = await setPostIsShow({
					id: this.item.id,
					is_show: this.item.is_show === 1 ? 0 : 1
				});
				if (res.code === 1) {
					uni.showToast({
						title: res.msg,
						icon: "none",
						mask: true,
					});


					this.$emit('refresh');
				}
			},
			async sureRemove() {
				const res = await myPostDel({
					id: this.item.id,
				});
				if (res.code === 1) {
					uni.showToast({
						title: res.msg,
						icon: "none",
						mask: true,
					});


					setTimeout(() => {
						this.$emit('refresh');
					}, 1500);

				}
			},
			remove() {
				uni.showModal({
					title: '提示',
					content: '确定删除该帖子吗？',
					success: (sub) => {
						if (sub.confirm) {
							this.sureRemove();
						} else if (sub.cancel) {}
					}
				});
			},
			goInfo() {
				if (this.item.is_show === 1) {
					uni.navigateTo({
						url: `/pagesCommunity/postInfo/postInfo?id=${this.item.id}`
					})
				}
			},
			goEdit() {
				uni.navigateTo({
					url: `/pagesCommunity/postMessage/postMessage?id=${this.item.id}`
				})
			}
		}
	}
</script>

<style lang="scss">
	.right {
		width: 61%;
		height: 115px;
	}

	.card {
		border-radius: 6px;

		.money {
			color: #F34184;
		}
	}

	.title {
		width: 75%;
	}
</style>
